package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/servletDemo")
public class ServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1获取虚拟目录名称getContextPath();
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
        //2获取Servlet映射路径getServletPath();
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        //3获取访问者ip getRemoteAddr();
        String ip = req.getRemoteAddr();
        System.out.println(ip);
        //4获取请求消息的数据 getQuerySting();
        String queryString = req.getQueryString();
        System.out.println(queryString);
        //5获取统一资源标识符getRequsetURI();
        String requestURI = req.getRequestURI();
        System.out.println(requestURI);
        //6获取统一资源定位符 getRequestURL
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
